home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 21
/
Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso
/
Aminet
/
util
/
cdity
/
availmem2.lha
/
AvailMem2
/
src
/
AvailMem2.s
< prev
next >
Wrap
Text File
|
1992-09-02
|
5KB
|
211 lines
;Program History:
;2.0ßeta0.1:
; Wrote simple startup and closedown code, easily callable
; like procedures.
* program includes
include "AvailMem2_gui.i"
incdir "!includes:OS3.0"
include "exec/exec.i"
include "dos/dos.i"
include "dos/dosextens.i"
include "graphics/gfx.i"
include "intuition/intuition.i"
include "libraries/commodites.i"
incdir "!includes:LVO"
include "exec_lib.i"
include "dos_lib.i"
include "graphics_lib.i"
include "intuition_lib.i"
* program exports
public _GadToolsBase
public _IntuitionBase
public _GfxBase
public _SysBase
* program structures
* program defines
_SysBase equ (4).w ;execbase constant
KICKVER equ 37 ;require OS2.0+
CONFVER equ 1 ;config-version
section code,code ;availmem code section
prg_Startup
move.l (4).w,a6 ;put execbase in a6
sub.l a1,a1 ;clear a1
jsr _LVOFindTask(a6) ;find this task
move.l d0,ptr_ThisTask ;store taskptr
move.l ptr_ThisTask,a4 ;put pointer to task in a4
tst.l pr_CLI(a4) ;check if started from CLI
bne .StartedFromCLI ;skip if launched from CLI
lea.l pr_MsgPort(a4),a0 ;get ptr to msgport
jsr _LVOWaitPort(a6) ;wait for msg-port
lea.l pr_MsgPort(a4),a0 ;get ptr to msgport
jsr _LVOGetMsg(a6) ;get waiting startup-message
move.l d0,ptr_StartupMsg ;store wbmessage
.StartedFromCLI
move.l (4).w,a6 ;put execbase in a6
lea.l _DosName,a1 ;get ptr to dos.library
move.l #KICKVER,d0 ;put kick version in d0
jsr _LVOOpenLibrary(a6) ;open dos.library
move.l d0,_DosBase ;store library base
beq prg_Fail ;bail out if failure
move.l (4).w,a6 ;put execbase in a6
lea.l _GfxName,a1 ;get ptr to graphics.library
move.l #KICKVER,d0 ;put kick version in d0
jsr _LVOOpenLibrary(a6) ;open graphics.library
move.l d0,_GfxBase ;store library base
beq prg_Fail ;bail out if failure
move.l (4).w,a6 ;put execbase in a6
lea.l _IntuitionName,a1 ;get ptr to intuition.library
move.l #KICKVER,d0 ;put kick version in d0
jsr _LVOOpenLibrary(a6) ;open intuition.library
move.l d0,_IntuitionBase ;store library base
beq prg_Fail ;bail out if failure
move.l (4).w,a6 ;put execbase in a6
lea.l _GadToolsName,a1 ;get ptr to gadtools.library
move.l #KICKVER,d0 ;put kick version in d0
jsr _LVOOpenLibrary(a6) ;open gadtools.library
move.l d0,_GadToolsBase ;store library base
beq prg_Fail ;bail out if failure
tst.l ptr_StartupMsg ;check if launched from WB
beq .NoDirWaiting ;skip if launched from CLI
move.l _DosBase,a6 ;put dosbase in a6
move.l ptr_StartupMsg,a2 ;get ptr to wbmessage
move.l sm_ArgList(a2),a2 ;get ptr to wbstartup-message
move.l wa_Lock(a2),d1 ;get currentdir lock
jsr _LVOCurrentDir(a6) ;set current directory
.NoDirWaiting
jsr SetupScreen ;initialize screen
tst.l d0 ;check if init worked
bne prg_Fail ;bail out if failure
prg_Main
prg_CloseDown
jsr CloseResizeWindow ;close resize window
jsr CloseSettingsWindow ;close settings window
jsr CloseMemoryDisplayWindow;close main window
jsr CloseDownScreen ;deinitalize screen
tst.l _GadToolsBase ;check if gadtools.library open
beq .no_gadtoolsbase ;skip if opening failed
move.l _GadToolsBase,a6 ;put gadtoolsbase in a6
move.l a6,a1 ;put gadtoolsbase in a1
move.l (4).w,a6 ;put execbase in a6
jsr _LVOCloseLibrary(a6) ;close gadtools.library
move.l #0,_GadToolsBase ;reset library base
.no_gadtoolsbase
tst.l _IntuitionBase ;check if intuition.library open
beq .no_intuitionbase ;skip if opening failed
move.l _IntuitionBase,a6 ;put intuitionbase in a6
move.l a6,a1 ;put intuitionbase in a1
move.l (4).w,a6 ;put execbase in a6
jsr _LVOCloseLibrary(a6) ;close intuition.library
move.l #0,_IntuitionBase ;reset library base
.no_intuitionbase
tst.l _GfxBase ;check if graphics.library open
beq .no_gfxbase ;skip if opening failed
move.l _GfxBase,a6 ;put gfxbase in a6
move.l a6,a1 ;put gfxbase in a1
move.l (4).w,a6 ;put execbase in a6
jsr _LVOCloseLibrary(a6) ;close graphics.library
move.l #0,_GfxBase ;reset library base
.no_gfxbase
tst.l _DosBase ;check if dos.library open
beq .no_dosbase ;skip if opening failed
move.l _DosBase,a6 ;put dosbase in a6
move.l a6,a1 ;put dosbase in a1
move.l (4).w,a6 ;put execbase in a6
jsr _LVOCloseLibrary(a6) ;close dos.library
move.l #0,_DosBase ;reset library base
.no_dosbase
tst.l ptr_StartupMsg ;check if message saved
beq .NoWBMessage ;skip if launched from CLI
move.l (4).w,a6 ;put execbase in a6
jsr _LVOForbid(a6) ;Forbid multitasking (No permit needed)
move.l ptr_StartupMsg,a1 ;put wbmessage in a1
jsr _LVOReplyMsg(a6) ;reply wbmessage
.NoWBMessage
move.l prg_Error,d0 ;put exitcode in d0
rts ;exit program
prg_Fail
move.l #20,prg_Error ;set program error
bra prg_CloseDown ;quit program
* subroutines
section data,data
_DosName dc.b "dos.library",0
_GfxName dc.b "graphics.library",0
_IntuitionName dc.b "intuition.library",0
_GadToolsName dc.b "gadtools.library",0
section bss,bss ;availmem bss sections
* library bases
_DosBase ds.l 1
_GfxBase ds.l 1
_IntuitionBase ds.l 1
_GadToolsBase ds.l 1
* program variables
ptr_ThisTask ds.l 1
ptr_StartupMsg ds.l 1
prg_Error ds.l 1
* program static structs
ptr_CxPort ds.l 1